<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>02-计算属性的复杂操作</title>
  <style>
    [v-cloak] {
      display: none;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <ul>
      <li v-for="item in books">{{item.name}}：{{item.price}}</li>
    </ul>
    <h2>总价格：{{totalPrice}}</h2>
  </div>
  <script src="../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        books: [{
          id: 110,
          name: 'Uinx编辑艺术',
          price: 119
        }, {
          id: 111,
          name: '代码大全',
          price: 105
        }, {
          id: 112,
          name: '深入理解计算机原理',
          price: 98
        }, {
          id: 113,
          name: '现代操作系统',
          price: 87
        }]
      },
      // computed 计算属性()
      computed: {
        totalPrice: function() {
          let result = 0;
          let books = this.books;
          for (let i = 0; i < books.length; i++) {
            result += books[i]['price'];
          }
          return result;
        }
      },
      // 自定义方法
      methods: {}
    })
  </script>
  <style>

  </style>
</body>

</html>